﻿// <copyright file="admin_Login.aspx.cs" company="NTalent">
// Copyright (c) 2010, NTalent, Inc. All rights reserved
// </copyright>
// <author>卢俊坤</author>
// <author>王彦博 符茂松</author>

using System;
using System.Web.Security;
using Net.Ntalent.Action50.Core.Controls;
using Net.Ntalent.Action50.Core.Service;
using Net.Ntalent.Action50.Core.Util;

/// <summary>
/// 登录页面
/// </summary>
///<author>王彦博</author> 
/// <copyright>
/// Copyright (c) 2010, NTalent, Co. Ltd. All rights reserved.
/// </copyright>
/// <version>1.0.0</version>
public partial class admin_Login : PageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
    }

    /// <summary>
    /// 点击登录按钮
    /// </summary>
    protected void LinkButton1_Click1(object sender, EventArgs e)
    {       
            var authenticationService = new AuthenticationService();
            string account = tb_Email.Text.Trim();
            string password = tb_Password.Text.Trim();
            password = FormsAuthentication.HashPasswordForStoringInConfigFile(password, "SHA1");

            string checkCode = tb_validateCode.Text.Trim();

            //验证码错误,提示错误并返回
            if (!authenticationService.CompareCheckCodes(checkCode))
            {
                Label_chechCodeMessage.Text = "check code error";
                span_info.Visible = false;
                return;
            }

            //进行account和password的验证
            if (authenticationService.IsAdmin(account, password))
            {
                authenticationService.LogIn(account, password);
                Response.Redirect("admin_Action_List.aspx");
            }
            else
            {
                //accout或password错误，提示错误并返回
                Label_errrMessage.Text = "account or password is wrong";
            }
    }
    protected void LinkButton_Logout_Click(object sender, EventArgs e)
    {
        var authenticationService = new AuthenticationService();
        authenticationService.LogOut();
        Response.Redirect(Request.UrlReferrer.ToString());
    }
}
